import request from "@/utils/request";
import { rootsUrl } from "../utils";
import { getToken } from "@/utils/auth";

/**
 * 投票活动--获取投票活动列表
 */
export const getVoteList = (pageIndex, pageSize) => {
  let token = getToken();
  return request({
    url: `${rootsUrl[3]}/cbculture/vote/getVoteList.shtml`,
    method: "get",
    params: {
      pageIndex,
      pageSize,
      token,
      source: "web"
    }
  });
};

/**
 * 获取投票活动详情
 * @param {Number} id 投票活动id
 */
export const getVoteDetail = id => {
  return request({
    url: `${rootsUrl[3]}/cbculture/vote/getVoteDetails.shtml`,
    method: "get",
    params: {
      id
    }
  });
};

/**
 * 投票活动--获取某个投票活动的选项列表
 * @param {Number} id 投票活动id
 */
export const getVoteItems = (id, userId, pageIndex) => {
  let token = getToken();
  return request({
    url: `${rootsUrl[3]}/cbculture/vote/getVoteItemList.shtml`,
    method: "get",
    params: {
      pageSize: 12,
      pageIndex,
      token,
      id,
      mid: userId
    }
  });
};

/**
 * 投票活动--获取投票活动选项详情
 * @param {NUmber} id
 */
export const getVoteItemDetail = (id, userId) => {
  return request({
    url: `${rootsUrl[3]}/cbculture/vote/getVoteItemDetails.shtml`,
    method: "get",
    params: {
      id,
      mid: userId
    }
  });
};

/**
 * 投票活动--给某个投票活动中的某个选项投票
 * @param {Number} id 某个投票活动中的某个选项的ID
 */
export const vote = (itemId, userId, id) => {
  let token = getToken();
  return request({
    url: `${rootsUrl[3]}/cbculture/vote/addOneVoteItemById.shtml`,
    method: "get",
    params: {
      token,
      id,
      mid: userId,
      nid: itemId
    }
  });
};
